package me.zhengjie.modules.workorder.repository;

import me.zhengjie.modules.workorder.domain.TAccident;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

/**
* @author zcw
* @date 2019-08-10
*/
@SuppressWarnings("rawtypes")
public interface TAccidentRepository extends JpaRepository<TAccident, Long>, JpaSpecificationExecutor {
	
	@Query(value="SELECT * from t_accident where NOT EXISTS (SELECT 1 from t_work_order where t_accident.id=t_work_order.source_id)",nativeQuery = true)
	public List<TAccident> findTAccidentWithOrder();

	@Modifying
	@Query(value="update t_accident set customer_name=:customer_name where customer_id=:customer_id",nativeQuery = true)
	public Integer updateCustomerName(@Param("customer_id") Long customer_id, @Param("customer_name") String customerName);
	
}